///PHILOTES Source Code.  (C)2012 PhiloLabs
#pragma once


#ifndef __MeshSerializer_H__
#define __MeshSerializer_H__

#include "OgrePrerequisites.h"
#include "OgreSerializer.h"
#include "OgreMeshSerializerImpl.h"


namespace Ogre {
	
	class MeshSerializerListener;
	
	/// Mesh compatibility versions
	enum MeshVersion 
	{
		/// Latest version available
		MESH_VERSION_LATEST,
		
		/// OGRE version v1.8+
		MESH_VERSION_1_8,
		/// OGRE version v1.7+
		MESH_VERSION_1_7,
		/// OGRE version v1.4+
		MESH_VERSION_1_4,
		/// OGRE version v1.0+
		MESH_VERSION_1_0,
		
		/// Legacy versions, DO NOT USE for writing
		MESH_VERSION_LEGACY
	};

	
	
	
    class _OgreExport MeshSerializer : public Serializer
    {
    public:
        MeshSerializer();
        virtual ~MeshSerializer();


        
        void exportMesh(const Mesh* pMesh, const String& filename,
			Endian endianMode = ENDIAN_NATIVE);

        
        void exportMesh(const Mesh* pMesh, const String& filename,
						MeshVersion version,
						Endian endianMode = ENDIAN_NATIVE);

        
        void exportMesh(const Mesh* pMesh, DataStreamPtr stream,
			Endian endianMode = ENDIAN_NATIVE);

        
        void exportMesh(const Mesh* pMesh, DataStreamPtr stream,
						MeshVersion version,
						Endian endianMode = ENDIAN_NATIVE);
        
		
        void importMesh(DataStreamPtr& stream, Mesh* pDest);

		/// Sets the listener for this serializer
		void setListener(MeshSerializerListener *listener);
		/// Returns the current listener
		MeshSerializerListener *getListener();
		
    protected:
		
		class MeshVersionData : public MemAlloc_General
		{
		public:
			MeshVersion version;
			String versionString;
			MeshSerializerImpl* impl;
			
			MeshVersionData(MeshVersion _ver, const String& _string, MeshSerializerImpl* _impl)
			: version(_ver), versionString(_string), impl(_impl) {}
			
			~MeshVersionData() { PHILO_DELETE impl; }
			
		};

        typedef vector<MeshVersionData*>::type MeshVersionDataList;
        MeshVersionDataList mVersionData;

		MeshSerializerListener *mListener;

    };

	
	class MeshSerializerListener
	{
	public:
		virtual ~MeshSerializerListener() {}
		/// Called to override the loading of the given named material
		virtual void processMaterialName(Mesh *mesh, String *name) = 0;
		/// Called to override the reference to a skeleton
		virtual void processSkeletonName(Mesh *mesh, String *name) = 0;
	};
	
	
}


#endif
